"""
子类中扩展property

问题：
    在子类中，你想要扩展定义在父类中的property的功能。
解决方案：
    子类继承自Person并扩展了父类的property的功能。
"""


class Person:
    def __init__(self):
        self._name = None

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value):
        if not isinstance(value, str):
            raise TypeError("Expected a string")

        self._name = value

    @name.deleter
    def name(self):
        raise AttributeError("Can't delete attribute")


class User(Person):
    @property
    def name(self):
        print("User get name")
        return super().name

    @name.setter
    def name(self, value):
        print("User set name")
        super(User, User).name.__set__(self, value)

    @name.deleter
    def name(self):
        print("User delete name ")
        super(User, User).name.__delete__(self)


def use_user():
    user = User()
    user.name = "Kevin"
    print(user.name)
    # del user.name
    # 输出结果：
    """
    User set name
    User get name
    Kevin
    """


if __name__ == '__main__':
    use_user()
